package entity;

import java.io.Serializable;
import java.util.Date;

public class WeatherForecast implements Serializable {
    
    private String city;
    private String countryCode;
    private int temperature;
    private String weatherType;
    private String weatherDescription;
    private String weatherIcon;
    private int rain;
    private int snow;
    private Date date;
    private WeatherType weather;

    public WeatherForecast() {
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public int getTemperature() {
        return temperature;
    }

    public void setTemperature(int temperature) {
        this.temperature = temperature;
    }

    public String getWeatherType() {
        return weatherType;
    }

    public void setWeatherType(String weatherType) {
        this.weatherType = weatherType;
    }

    public String getWeatherDescription() {
        return weatherDescription;
    }

    public void setWeatherDescription(String weatherDescription) {
        this.weatherDescription = weatherDescription;
    }

    public String getWeatherIcon() {
        return weatherIcon;
    }

    public void setWeatherIcon(String weatherIcon) {
        this.weatherIcon = weatherIcon;
    }

    public int getRain() {
        return rain;
    }

    public void setRain(int rain) {
        this.rain = rain;
    }

    public int getSnow() {
        return snow;
    }

    public void setSnow(int snow) {
        this.snow = snow;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public WeatherType getWeather() {
        return weather;
    }

    public void setWeather(WeatherType weather) {
        this.weather = weather;
    }
    
    public String getCityCountry() {
        return city + ", " + countryCode;
    }
    
    public String getFormattedWeather() {
        String output = weatherType + ": " + weatherDescription + ".";
        if (weather == WeatherType.DRIZZLY || weather == WeatherType.RAINY) {
            output += " Rain amount: " + rain + "mm";
        }
        else if (weather == WeatherType.SNOWY) {
            output += " Snow amount:" + snow + "mm";
        }
        return output;
    }
    
    public static WeatherType parseOrNone(String weatherType, String weatherDescription) {
        WeatherType weather = WeatherType.NONE;
        if (weatherType.equalsIgnoreCase("Clear")) {
            weather = WeatherType.SUNNY;
        }
        else if (weatherType.equalsIgnoreCase("Clouds")) {
            if (weatherType.contains("clear") || weatherType.contains("few")) {
                weather = WeatherType.SUNNY;
            }
            else {
                weather = WeatherType.CLOUDY;
            }
        }
        else if (weatherType.equalsIgnoreCase("Rain")) {
            if (weatherType.contains("drizzle") || weatherType.contains("shower")) {
                weather = WeatherType.DRIZZLY;
            }
            else {
                weather = WeatherType.RAINY;
            }
        }
        else if (weatherType.equalsIgnoreCase("Snow")) {
            weather = WeatherType.SNOWY;
        }
        return weather;
    }

    public boolean isBad(String badWeatherThreshold) {
        WeatherType threshold = WeatherType.valueOf(badWeatherThreshold);
        return weather.ordinal() >= threshold.ordinal();
    }
}
